package com.itheima.controller;

import com.itheima.domain.pojo.Clazz;
import com.itheima.domain.query.QueryParam;
import com.itheima.domain.vo.PageResult;
import com.itheima.domain.vo.Result;
import com.itheima.service.ClazzService;
import org.apache.ibatis.annotations.Select;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.List;

/**
 * @Author:篍
 * @Date: 2025/07/10 18:55
 * @Description:
 */
@RestController
@RequestMapping("/clazzs")
public class ClazzController {
    @Autowired
    ClazzService clazzService;

    /**
     * 添加班级
     * @param clazz
     * @return Result
     */
    @PostMapping
    public Result addClazz(@RequestBody Clazz clazz){
        clazzService.addClazz(clazz);
        return Result.success();
    }

    /**
     * 分页查询符合条件的班级
     *
     * @return Result
     */
    @GetMapping()
    public Result listAllClazz(QueryParam queryParam){
        PageResult<Clazz> clazzs=clazzService.findClazz(queryParam);
        return Result.success(clazzs);
    }

    /**
     *删除班级
     * @param id
     * @return
     */
    @DeleteMapping("/{id}")
    public Result deleteClazz(@PathVariable("id") Integer id){
        clazzService.deleteClazzById(id);
        return Result.success();
    }

    @GetMapping("/{id}")
    public Result findById(@PathVariable("id") Integer id){
        Clazz clazz=clazzService.findById(id);
        return Result.success(clazz);
    }

    @PutMapping
    public Result updateById(@RequestBody Clazz clazz){
        clazzService.updateClazz(clazz);
        return Result.success();
    }

    /**
     * 查询所有班级
     * @return
     */
    @GetMapping("/list")
    public Result findAllClazz(){
        return Result.success(clazzService.findAllClazz());
    }

}
